; PE importing by ordinal (his own exports)

; Ange Albertini, BSD LICENCE 2011-2013

%include 'consts.inc'

%include 'headers.inc'

istruc IMAGE_DATA_DIRECTORY_16
    at IMAGE_DATA_DIRECTORY_16.ExportsVA, dd Exports_Directory - IMAGEBASE
    at IMAGE_DATA_DIRECTORY_16.ImportsVA, dd import_descriptor - IMAGEBASE
iend

%include 'section_1fa.inc'

EntryPoint:
    jmp [__imp__export]
_c
Export1:
    push export
    call [__imp__printf]
    add esp, 1 * 4
    retn
_c

export db " * imports resolving to its own exports", 0ah, 0
_d

msvcrt.dll_iat:
__imp__printf:
    dd hnprintf - IMAGEBASE
    dd 0
impbyord.exe_iat:
__imp__export:
    dd impbyord.exe_hintnames - IMAGEBASE
    dd 0
_d

import_descriptor:
_import_descriptor msvcrt.dll
_import_descriptor impbyord.exe
istruc IMAGE_IMPORT_DESCRIPTOR
iend

msvcrt.dll_hintnames:
    dd hnprintf - IMAGEBASE
    dd 0

impbyord.exe_hintnames:
    dd 1 << 31 | 35
    dd 0

hnprintf:
    dw 0
    db 'printf', 0

msvcrt.dll db 'msvcrt.dll', 0
impbyord.exe db 'impbyord.exe', 0

Exports_Directory:
istruc IMAGE_EXPORT_DIRECTORY
  at IMAGE_EXPORT_DIRECTORY.nBase,             dd 35
  at IMAGE_EXPORT_DIRECTORY.NumberOfFunctions, dd 1
  at IMAGE_EXPORT_DIRECTORY.AddressOfFunctions,dd address_of_functions - IMAGEBASE
iend
_d

address_of_functions:
    dd Export1 - IMAGEBASE
_d

align FILEALIGN, db 0
